﻿using System;
using System.Data;
using System.Collections.Generic;

using Catering_Model;
namespace Catering_Rules
{
    /// <summary>
    /// RecipeInformation
    /// </summary>
    public partial class T_RecipeInformation
    {
        private readonly Catering_Operation.D_RecipeInformation dal = new Catering_Operation.D_RecipeInformation();
        public T_RecipeInformation()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Catering_Model.E_RecipeInformation model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Catering_Model.E_RecipeInformation model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return dal.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return dal.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Catering_Model.E_RecipeInformation GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Catering_Model.E_RecipeInformation GetModelByCache(int id)
        {

            string CacheKey = "RecipeInformationModel-" + id;
            object objModel = Catering_DBOpertion.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(id);
                    if (objModel != null)
                    {
                        int ModelCache = Catering_DBOpertion.ConfigHelper.GetConfigInt("ModelCache");
                        Catering_DBOpertion.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Catering_Model.E_RecipeInformation)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 获取数量
        /// </summary>
        /// <param name="strwhere"></param>
        /// <returns></returns>
        public int GetCount(string strwhere)
        {
            return dal.GetCount(strwhere);
        }

        /// <summary>
        /// 根据条件获取周食谱清单
        /// </summary>
        public DataSet GetWeekList(string ClassID, string FID, string Date)
        {
            return dal.GetWeekList(ClassID, FID, Date);

        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }

        /// <summary>
        /// 获取视图View_RecipesInformation表内容
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns>AID：RecipeInformationInfo表ID</returns>
        /// <returns>RecipeInformationID：RecipeInformation表ID</returns>
        /// <returns>RawID：RawMaterial表ID</returns>
        /// <returns>Number：此原料的重量（以克为单位）</returns>
        /// <returns>FMID：FoodMealType表ID</returns>
        /// <returns>Date：食谱中配餐的时间</returns>
        /// <returns>CID：Dish表ID</returns>
        /// <returns>RecipesID：Recipes表ID</returns>
        /// <returns>dayofweek：一周中的第几天（周日为0）</returns>
        /// <returns>RAWName：RawMaterial表RawName</returns>
        /// <returns>DishName：Dish表Name</returns>
        /// <returns>WeekNo：第几周（从0开始，0代表第一周）</returns>
        /// <returns>DTID：DishType表ID（是主食还是小菜、汤类、粥等）</returns>
        /// <returns>RecipesWeekID:RecipesWeek表ID</returns>
        public DataTable GetViewList(string strWhere)
        {
            return dal.GetViewList(strWhere).Tables[0];
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.E_RecipeInformation> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Catering_Model.E_RecipeInformation> DataTableToList(DataTable dt)
        {
            List<Catering_Model.E_RecipeInformation> modelList = new List<Catering_Model.E_RecipeInformation>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Catering_Model.E_RecipeInformation model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Catering_Model.E_RecipeInformation();
                    if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["FMID"] != null && dt.Rows[n]["FMID"].ToString() != "")
                    {
                        model.FMID = int.Parse(dt.Rows[n]["FMID"].ToString());
                    }
                    if (dt.Rows[n]["Date"] != null && dt.Rows[n]["Date"].ToString() != "")
                    {
                        model.Date = DateTime.Parse(dt.Rows[n]["Date"].ToString());
                    }
                    if (dt.Rows[n]["CID"] != null && dt.Rows[n]["CID"].ToString() != "")
                    {
                        model.CID = int.Parse(dt.Rows[n]["CID"].ToString());
                    }
                    if (dt.Rows[n]["MID"] != null && dt.Rows[n]["MID"].ToString() != "")
                    {
                        model.MID = int.Parse(dt.Rows[n]["MID"].ToString());
                    }
                    if (dt.Rows[n]["Week"] != null && dt.Rows[n]["Week"].ToString() != "")
                    {
                        model.Week = int.Parse(dt.Rows[n]["Week"].ToString());
                    }
                    if (dt.Rows[n]["Back"] != null && dt.Rows[n]["Back"].ToString() != "")
                    {
                        model.Back = dt.Rows[n]["Back"].ToString();
                    }
                    if (dt.Rows[n]["AVGWeight"] != null && dt.Rows[n]["AVGWeight"].ToString() != "")
                    {
                        model.AVGWeight = dt.Rows[n]["AVGWeight"].ToString();
                    }
                    if (dt.Rows[n]["Weight"] != null && dt.Rows[n]["Weight"].ToString() != "")
                    {
                        model.Weight = dt.Rows[n]["Weight"].ToString();
                    }
                    if (dt.Rows[n]["Price"] != null && dt.Rows[n]["Price"].ToString() != "")
                    {
                        model.Price = decimal.Parse(dt.Rows[n]["Price"].ToString());
                    }
                    if (dt.Rows[n]["temp1"] != null && dt.Rows[n]["temp1"].ToString() != "")
                    {
                        model.temp1 = dt.Rows[n]["temp1"].ToString();
                    }
                    if (dt.Rows[n]["temp2"] != null && dt.Rows[n]["temp2"].ToString() != "")
                    {
                        model.temp2 = dt.Rows[n]["temp2"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 检查 食谱
        /// </summary>
        /// <param name="classID">班组ID</param>
        /// <param name="FoodID">餐别ID 0表示所有餐别</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="ExamineUserID">检查人用户ID</param>
        /// <param name="ExamineUserName">检查人用户名</param>
        /// <returns>是否检查成功</returns>
        public bool Examine(int classID, int FoodID, string startDate, string endDate, int ExamineUserID, string ExamineUserName)
        {
            return dal.Examine(classID, FoodID, startDate, endDate, ExamineUserID, ExamineUserName);
        }

        /// <summary>
        /// 获取检查数据
        /// </summary>
        /// <param name="classID">班组ID</param>
        /// <param name="FoodID">餐别ID</param>
        /// <param name="startDate">日期</param>
        /// <returns>返回所需要查询的餐别数据</returns>
        public DataTable GetExamineDt(int classID, int FoodID, string strDate)
        {
            return dal.GetExamineDt(classID, FoodID, strDate);
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method

        #region 扩展方法
        /// <summary>
        /// 批量删除
        /// </summary>
        public bool DeleteListBywhere(string where)
        {
            return dal.DeleteListBywhere(where);
        }

        /// <summary>
        /// 判断该条件下的食谱是否存在检查
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public bool IsExistsExamineByWhere(string where)
        {
            return dal.IsExistsExamineByWhere(where);
        }


        /// <summary>
        /// 获取食谱检查报表
        /// </summary>
        /// <param name="StartTime">日期开始时间</param>
        /// <param name="EndTime">日期结束时间</param>
        /// <param name="strWhere">食谱查询条件</param>
        /// <returns></returns>
        public DataTable GetExamineDtForMonitor(string StartTime, string EndTime, string strWhere)
        {
            return dal.GetExamineDtForMonitor(StartTime, EndTime, strWhere);
        }
        #endregion
    }
}

